package jd;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.Iterator;

public class demo2 {
    public static void main(String[] args) throws DocumentException {
        Document doc=null;
        SAXReader saxReader=new SAXReader();
        doc=saxReader.read(new File("src/jd/demo1.xml"));

        //获取XML的根节点
        Element root=doc.getRootElement();
        //遍历Student
        for (Iterator itStudent = root.elementIterator();itStudent.hasNext();){
            Element student= (Element) itStudent.next();
            System.out.println(student.attributeValue("id"));
            for (Iterator it=student.elementIterator();it.hasNext();){
             Element its= (Element) it.next();
                System.out.println(its.getText());
            }
        }
    }
}
